{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "65dbad34",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我爱你 0\n",
      "我爱你 1\n",
      "我爱你 2\n",
      "我爱你 3\n",
      "我爱你 4\n",
      "我爱你 5\n",
      "我爱你 6\n",
      "我爱你 7\n",
      "我爱你 8\n",
      "我爱你 9\n",
      "我爱你 10\n",
      "我爱你 11\n",
      "我爱你 12\n",
      "我爱你 13\n",
      "我爱你 14\n",
      "我爱你 15\n",
      "我爱你 16\n",
      "我爱你 17\n",
      "我爱你 18\n",
      "我爱你 19\n",
      "我爱你 20\n",
      "我爱你 21\n",
      "我爱你 22\n",
      "我爱你 23\n",
      "我爱你 24\n",
      "我爱你 25\n",
      "我爱你 26\n",
      "我爱你 27\n",
      "我爱你 28\n",
      "我爱你 29\n",
      "我爱你 30\n",
      "我爱你 31\n",
      "我爱你 32\n",
      "我爱你 33\n",
      "我爱你 34\n",
      "我爱你 35\n",
      "我爱你 36\n",
      "我爱你 37\n",
      "我爱你 38\n",
      "我爱你 39\n",
      "我爱你 40\n",
      "我爱你 41\n",
      "我爱你 42\n",
      "我爱你 43\n",
      "我爱你 44\n",
      "我爱你 45\n",
      "我爱你 46\n",
      "我爱你 47\n",
      "我爱你 48\n",
      "我爱你 49\n",
      "我爱你 50\n",
      "我爱你 51\n",
      "我爱你 52\n",
      "我爱你 53\n",
      "我爱你 54\n",
      "我爱你 55\n",
      "我爱你 56\n",
      "我爱你 57\n",
      "我爱你 58\n",
      "我爱你 59\n",
      "我爱你 60\n",
      "我爱你 61\n",
      "我爱你 62\n",
      "我爱你 63\n",
      "我爱你 64\n",
      "我爱你 65\n",
      "我爱你 66\n",
      "我爱你 67\n",
      "我爱你 68\n",
      "我爱你 69\n",
      "我爱你 70\n",
      "我爱你 71\n",
      "我爱你 72\n",
      "我爱你 73\n",
      "我爱你 74\n",
      "我爱你 75\n",
      "我爱你 76\n",
      "我爱你 77\n",
      "我爱你 78\n",
      "我爱你 79\n",
      "我爱你 80\n",
      "我爱你 81\n",
      "我爱你 82\n",
      "我爱你 83\n",
      "我爱你 84\n",
      "我爱你 85\n",
      "我爱你 86\n",
      "我爱你 87\n",
      "我爱你 88\n",
      "我爱你 89\n",
      "我爱你 90\n",
      "我爱你 91\n",
      "我爱你 92\n",
      "我爱你 93\n",
      "我爱你 94\n",
      "我爱你 95\n",
      "我爱你 96\n",
      "我爱你 97\n",
      "我爱你 98\n",
      "我爱你 99\n"
     ]
    }
   ],
   "source": [
    "#while True 一般用于不确定的循环次数或无限次循环操作。\n",
    "\n",
    "count = 0\n",
    "while True:\n",
    "    print(\"我爱你\",count)\n",
    "    count +=1\n",
    "    if count == 100:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "e1d338b2",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-31-5f9deb9bb42b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mhide_card\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mint\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"hide_card：\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py\u001b[0m in \u001b[0;36mraw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m    858\u001b[0m                 \u001b[1;34m\"raw_input was called, but this frontend does not support input requests.\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    859\u001b[0m             )\n\u001b[1;32m--> 860\u001b[1;33m         return self._input_request(str(prompt),\n\u001b[0m\u001b[0;32m    861\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent_ident\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    862\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent_header\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py\u001b[0m in \u001b[0;36m_input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m    902\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    903\u001b[0m                 \u001b[1;31m# re-raise KeyboardInterrupt, to truncate traceback\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 904\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Interrupted by user\"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    905\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    906\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlog\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwarning\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Invalid Message:\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mexc_info\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "hide_card = int (input(\"hide_card：\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b9095d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import getpass\n",
    "hide_card = int (getpass.getpass(\"hide_card：\"))\n",
    "count = 0\n",
    "if hide_card <100 and hide_card>0:\n",
    "    print(\"游戏开始了\")\n",
    "    while True:\n",
    "        if count <5:\n",
    "            guess_dugit = int(input(\"guess_digit:\"))\n",
    "            if guess_digit == hide_card:\n",
    "                print (\"yes,you got it.\")\n",
    "                break\n",
    "            elif gurss_digt > hide_card:\n",
    "                print(\"往小的猜猜...\")\n",
    "            else:\n",
    "                print(\"往大的猜猜\")\n",
    "            count = count+1\n",
    "        else:\n",
    "            print(\"猜这么多次都不对，真6\")\n",
    "            print(\"正确答案是:%s\"%hide_card)\n",
    "            break\n",
    "else:\n",
    "    print(\"请输入数字0-99之间\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "396125df",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32069115",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额10\n",
      "------商品列表------\n",
      "0 商品1 7元\n",
      "1 商品2 6元\n",
      "2 商品3 8元\n",
      "请输入商品编号1\n",
      "购买成功,您的余额还有:4元\n",
      "------商品列表------\n",
      "0 商品1 7元\n",
      "1 商品2 6元\n",
      "2 商品3 8元\n"
     ]
    }
   ],
   "source": [
    "good_list = [\n",
    "    [\"商品1\",7],\n",
    "    [\"商品2\",6],\n",
    "    [\"商品3\",8]\n",
    "]\n",
    "shopping_list = []\n",
    "\n",
    "Alipay = int (input(\"请输入余额\"))\n",
    "\n",
    "while True:\n",
    "    print(\"------商品列表------\")\n",
    "    for i in range(3):\n",
    "        print(i,good_list[i][0],str(good_list[i][1])+\"元\")\n",
    "\n",
    "    user_choice = (input(\"请输入商品编号\"))\n",
    "    if user_choice.isdigit() and int(user_choice)<len(good_list) and int(user_choice)>=0:\n",
    "        user_choice = int(user_choice)\n",
    "\n",
    "        if Alipay > good_list[user_choice][1]:\n",
    "\n",
    "            Alipay = Alipay - good_list[user_choice][1]\n",
    "            shopping_list.append(good_list[user_choice])\n",
    "            print(\"购买成功,您的余额还有:%s元\"%(Alipay))\n",
    "\n",
    "        else:\n",
    "            print(\"您的余额不足\"+str(good_list[user_choice][1])+\"元，请更换支付方式\")\n",
    "\n",
    "    elif user_choice == \"Q\":\n",
    "        print(\"感谢您的购买，欢迎下次光临！\")\n",
    "        print(\"您的购物车，shopping_list\")\n",
    "        print(\"您的余额还有，Alipay\")\n",
    "        break\n",
    "    else:\n",
    "        print(\"您输入的商品不存在或内容有误！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "033e639d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd9786b5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
